<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%--

   这代码是复制更新页面的，具体有些注释可能写的有问题

--%>
<script type="application/javascript">
    $(function () {
        $("#rolePageBody").on("click", ".removeBtn", function () {
            // 打开模态框
            $("#deleteModal").modal("show");
            // 获取表格中当前行中的角色名称
            var roleName = $(this).parent().prev().text();

            window.roleId = this.id;
            // 使用 roleName 的值设置模态框中的文本框
            $("#deleteModal [name=roleName]").val(roleName);
        });

        // 7.给删除模态框中的删除按钮绑定单击响应函数
        $("#deleteRoleBtn").click(function () {
            // ①从文本框中获取新的角色名称
            var roleName = $("#editModal [name=roleName]").val();

            // ②发送 Ajax 请求执行删除
            $.ajax({
                "url": "role/delete.json",
                "type": "post",
                "data": {
                    "id": window.roleId,
                    "name": roleName
                },
                "dataType": "json",
                "success": function (response) {
                    var result = response.result;
                    if (result == "SUCCESS") {
                        layer.msg("操作成功！");
                        // 重新加载分页数据
                        generatePage();
                    }
                    if (result == "FAILED") {
                        layer.msg("操作失败！" + response.message);
                    }
                }, "error": function (response) {
                    layer.msg(response.status + " " + response.statusText);
                }
            });
            // ③关闭模态框
            $("#deleteModal").modal("hide");
        });
    })


</script>


<div id="deleteModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">尚筹网系统弹窗</h4>
            </div>
            <div class="modal-body">
                <form class="form-signin" role="form">
                    <div class="form-group has-success has-feedback">
                        <input type="text" name="roleName" class="form-control" readonly="readonly" autofocus>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button id="deleteRoleBtn" type="button" class="btn btn-success"> 删 除
                </button>
            </div>
        </div>
    </div>
</div>